home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
windows4
/
plx17.zip
/
METER.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-06-14
|
4KB
|
155 lines
{Meter - A Spin Control Window}
unit Meter;
{$R Meter.res}
{$D Copyright (c) 1992 Doug Overmyer}
{********************** Interface *************************}
interface
uses WinTypes, WinProcs, WinDos, Strings, WObjects,WFPlus;
type
PMeterWindow = ^TMeterWindow;
TMeterWindow = object(TWindow)
BI:TBitmap;
ThePen:HPen;
PctDone :Integer;
BMP:HBitmap;
StartPT,EndPT:TPoint;
IsPainted:Boolean;
constructor Init(AParent:PWindowsObject;ATitle:PChar);
function GetClassName:PChar;virtual;
procedure SetupWindow;virtual;
destructor Done; virtual;
procedure Draw(NewPctDone:Integer);virtual;
procedure Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);virtual;
procedure GetEndPt;virtual;
end;
{************************ Implementation ********************}
implementation
function SetPoint(X,Y:Integer;PT:PPoint):PPoint;
begin
PT^.x := X;
PT^.Y := Y;
SetPoint := PT;
end;
{*************************** TMeterWindow ***********************}
constructor TMeterWindow.Init(Aparent:PWindowsObject;ATitle:PChar);
var
DC:HDC;
CXBorder,CYBorder,CYCaption:Integer;
begin
TWindow.Init(AParent,ATitle);
DisableAutoCreate;
ThePen := CreatePen(ps_Solid,2,RGB(255,0,0));
DC := CreateDC('Display', Nil, Nil, Nil);
CXBorder := GetSystemMetrics(SM_CXBORDER);
CYBorder := GetSystemMetrics(SM_CYBORDER);
CYCaption := GetSystemMetrics(SM_CYCAPTION);
DeleteDC(DC);
BMP := LoadBitmap(HInstance,'Meter');
GetObject(BMP,sizeof(TBitmap),@BI);
with Attr do
begin
X := 100;Y :=100 ;
W := BI.bmWidth+(2*CXBorder);
H := BI.bmHeight+CYBorder+CYCaption;
Style := ws_Popup or ws_Visible or ws_Border or ws_Caption;
end;
PctDone := -1;
SetPoint(75,90,@StartPt);
SetPoint(75,90,@EndPt);
IsPainted := False;
end;
function TMeterWindow.GetClassName:PChar;
begin
GetClassName := 'MeterWindow';
end;
procedure TMeterWindow.SetupWindow;
begin
TWindow.SetupWindow;
end;
destructor TMeterWindow.Done;
begin
DeleteObject(ThePen);
DeleteObject(BMP);
TWindow.Done;
end;
procedure TMeterWindow.Draw(NewPctDone:Integer);
var
Rgn:TRect;
DC:HDC;
OldPen:HPen;
begin
PctDone := NewPctDone;
if IsPainted then
begin
DC := GetDC(HWindow);
SetROP2(DC,R2_XORPen);
OldPen := SelectObject(DC,ThePen);
MoveTo(DC,StartPt.X,StartPt.Y); {Erase the last line}
LineTo(DC,EndPT.X,EndPT.Y);
GetEndPt;
MoveTo(DC,StartPt.X,StartPt.Y);
LineTo(DC,EndPT.X,EndPT.Y);
SelectObject(DC,OldPen);
ReleaseDC(HWindow,DC);
end;
end;
procedure TMeterWindow.Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);
var
OldPen :HPen;
OldBMP:HBitmap;
MemDC:HDC;
begin
IsPainted := True;
MemDC :=CreateCompatibleDC(PaintDC);
OldBMP := SelectObject(MemDC,BMP);
BitBlt(PaintDC, 0, 0,BI.bmWidth,BI.bmHeight, MemDC, 0, 0, SRCCopy);
SelectObject(MemDC,OldBmp);
DeleteDC(MemDC);
GetEndPt;
OldPen := SelectObject(PaintDC,ThePen);
SetROP2(PaintDC,R2_XORPen);
MoveTo(PaintDC,StartPt.X,StartPt.Y);
LineTo(PaintDC,EndPT.X,EndPT.Y);
SelectObject(PaintDC,OldPen);
end;
procedure TMeterWindow.GetEndPt;
begin
Case PctDone of
-1:SetPoint(38,85,@EndPt);
00:SetPoint(38,85,@EndPT); {76}
05:SetPoint(39,72,@EndPt);
10:SetPoint(41,67,@EndPT);
15:SetPoint(42,63,@EndPt);
20:SetPoint(44,61,@EndPT);
25:SetPoint(45,59,@EndPt);
30:SetPoint(47,57,@EndPt);
35:SetPoint(51,53,@EndPt);
40:SetPoint(56,50,@EndPT);
45:SetPoint(66,47,@EndPt);
50:SetPoint(75,45,@EndPT);
55:SetPoint(85,48,@EndPt);
60:SetPoint(94,50,@EndPT);
65:SetPoint(99,54,@EndPt);
70:SetPoint(104,57,@EndPT);
75:SetPoint(105,59,@EndPt);
80:SetPoint(106,61,@EndPT);
85:SetPoint(108,64,@EndPT);
90:SetPoint(110,67,@EndPT);
95:SetPoint(112,72,@EndPt);
100:SetPoint(114,76,@EndPt);
else
begin
EndPt.X := EndPt.X ;
EndPt.Y := EndPt.Y ;
end;
end;
end;
end.